Ext.define('Gigi.view.user.EditForm', {
	extend : 'Ext.form.Panel',
	alias : 'widget.userform',

	frame : true,
	bodyPadding : 5,
	layout: 'anchor',

	defaults: {
		labelAlign : 'right',
		labelWidth : 70,
		anchor: '100%'
	},

	items : [ {
		xtype : 'textfield',
		name : 'username',
		fieldLabel : '用户名',
		allowBlank: false
	}, {
		xtype : 'radiogroup',
		fieldLabel : '启用',
		name : 'rgEnabled',
		items: [
			{ boxLabel: '是', name: 'enabled', inputValue: 'true', checked : true},
			{ boxLabel: '否', name: 'enabled', inputValue: 'false'}
		]
	}, {
		xtype : 'radiogroup',
		fieldLabel : '账号锁定',
		name : 'rgAccountNonLocked',
		items: [
			{ boxLabel: '是', name: 'accountNonLocked', inputValue: 'false' },
			{ boxLabel: '否', name: 'accountNonLocked', inputValue: 'true', checked : true}
		]
	}, {
		xtype : 'radiogroup',
		fieldLabel : '账号过期',
		name : 'rgAccountNonExpired',
		items: [
			{ boxLabel: '是', name: 'accountNonExpired', inputValue: 'false' },
			{ boxLabel: '否', name: 'accountNonExpired', inputValue: 'true', checked : true}
		]
	}, {
		xtype : 'radiogroup',
		fieldLabel : '密码过期',
		name : 'rgCredentialsNonExpired',
		items: [
			{ boxLabel: '是', name: 'credentialsNonExpired', inputValue: 'false' },
			{ boxLabel: '否', name: 'credentialsNonExpired', inputValue: 'true', checked : true}
		]
	}, {
		xtype : 'textfield',
		name : 'email',
		fieldLabel : 'Email'
	} ],

	loadRecord : function(record) {
		this.callParent(arguments);
		var rgEnabled = this.down('[name=rgEnabled]');
		rgEnabled.setValue({enabled : record.get('enabled').toString()});
		var rgAccountNonLocked = this.down('[name=rgAccountNonLocked]');
		rgAccountNonLocked.setValue({accountNonLocked : record.get('accountNonLocked').toString()});
		var rgAccountNonExpired = this.down('[name=rgAccountNonExpired]');
		rgAccountNonExpired.setValue({accountNonExpired : record.get('accountNonExpired').toString()});
		var rgCredentialsNonExpired = this.down('[name=rgCredentialsNonExpired]');
		rgCredentialsNonExpired.setValue({credentialsNonExpired : record.get('credentialsNonExpired').toString()});
	},

	initComponent : function() {
		if (this.initialConfig  && ('update' == this.initialConfig.actionType)) {
			this.items[0].readOnly = true;
		} else {
			this.items[0].readOnly = false;
		}
		this.callParent(arguments);
	}
});

Ext.define('Gigi.view.user.Edit', {
	extend : 'Ext.window.Window',
	alias : 'widget.useredit',

	layout : 'fit',
	autoShow : true,
	actionType : 'create',

	initComponent : function() {
		var form = Ext.widget('userform', {actionType : this.actionType});
		this.items = [form];
		this.buttons = [ {
			text : '保存',
			action : 'save'
		}, {
			text : '取消',
			scope : this,
			handler : this.close
		} ];
		this.callParent(arguments);
	}
});